Systems and methods for mapping and routing based on clustering

ABSTRACT

Unique identifiers (IDs) associated with a plurality of nodes may be provided. Nodes clustered within a community may be assigned numerically proximate unique IDs. A number of partitions associated with a plurality of machines may be determined. The unique IDs may be segmented into divisions based on the number of partitions. The unique IDs may be mapped to the plurality of machines based on the divisions.

FIELD OF THE INVENTION

The present invention relates to the field of clustering. Moreparticularly, the present invention provides techniques for mappingusers based on clustering.

BACKGROUND

Social networking websites provide a dynamic environment in whichmembers can connect to and communicate with other members. Thesewebsites may commonly provide online mechanisms allowing members tointeract within their preexisting social networks, as well as create newsocial networks. Members may include any individual or entity, such asan organization or business. Among other attributes, social networkingwebsites allow members to effectively and efficiently communicaterelevant information to their social networks.

A member of a social network may highlight or share information, newsstories, relationship activities, music, video, and any other content ofinterest to areas of the website dedicated to the member or otherwisemade available for such content. Other members of the social network mayaccess the shared content by browsing member profiles or performingdedicated searches. Upon access to and consideration of the content, theother members may react by taking one or more responsive actions, suchas providing feedback or an opinion about the content. The ability ofmembers to interact in this manner fosters communications among them andhelps to realize the goals of social networking websites.

Even routine usage of social networks may involve creation of largevolumes of data over a vast array of computing resources. The ability tomanage such volumes of data in a manner consistent with memberexpectations is important to optimal operation of social networks. Forexample, in their interactions with others, members who requestresources of the social network desire timely presentation ofinformation. As another example, members who may perform searches on thedata maintained by the social network expect a timely return of searchresults.

SUMMARY

To cluster nodes and map the nodes to computing resources for optimalsystem performance, computer implemented methods, systems, and computerreadable media, in an embodiment, may provide unique identifiers (IDs)associated with a plurality of nodes. Nodes clustered within a communitymay be assigned numerically proximate unique IDs. A number of partitionsassociated with a plurality of machines may be determined. The uniqueIDs may be segmented into divisions based on the number of partitions.The unique IDs may be mapped to the plurality of machines based on thedivisions.

In an embodiment, the plurality of machines may include a cache layer.

In an embodiment, a query associated with a node may be received. Aunique ID for the node may be determined. A machine to which the node ismapped based on the unique ID may be determined. The query may be routedto the machine.

In an embodiment, a unique ID associated with a node may be determinedbased on a mapping of preexisting IDs to the unique IDs.

In an embodiment, a query associated with a node may be received. Aunique ID for the node may be determined. A first machine to which thenode is mapped may be determined based on the unique ID. A load of themachine exceeding a threshold may be detected. The query may be routedto a second machine.

In an embodiment, two or more geographic locations with complementarytraffic usage patterns may be detected. Unique IDs associated with thetwo or more geographic locations with complementary traffic usagepatterns may be mapped to a machine.

In an embodiment, the two or more geographic locations may be countries.

In an embodiment, the complementary traffic usage patterns may includehigh traffic usage and low traffic usage according to time.

In an embodiment, an impact to locality may be determined. The mappingof unique IDs may be in response to the determined impact.

In an embodiment, a query associated with a unique ID associated withone of the two or more geographic locations may be received. The querymay be routed to the machine.

In an embodiment, two or more geographic locations having different timezones may be detected. Unique IDs associated with the two or moregeographic locations may be mapped to a machine.

In an embodiment, a machine having a load above a threshold may bedetected. At least one unique ID may be mapped away from the machine.

In an embodiment, a prohibited application associated with an unusedshard of a machine may be identified. The prohibited application may beunavailable to users associated with a first geographic location.Additional unique IDs may be mapped to the unused shard of the machine.The additional unique IDs may be associated with users associated with asecond geographic location.

In an embodiment, the mapping of the unique IDs to the plurality ofmachines may include evenly distributing the unique IDs.

In an embodiment, the mapping of the unique IDs to the plurality ofmachines may include unevenly distributing the unique IDs.

In an embodiment, the plurality of nodes may be associated with users ofa social networking system.

In an embodiment, the plurality of nodes may be associated with at leastone of persons, non-persons, organizations, content, events, web pages,communications, objects, or concepts.

In an embodiment, the grouping of the classifications into first levelcommunities may include maximizing at least one of a number ofconnections or a strength of connections within a community, andminimizing at least one of a number of connections or a strength ofconnections between communities.

Many other features and embodiments of the invention will be apparentfrom the accompanying drawings and from the following detaileddescription.

BRIEF DESCRIPTION OF THE DRAWINGS

FIG. 1 illustrates an example clustering module, according to anembodiment of the present disclosure.

FIG. 2 illustrates an example identification module, according to anembodiment of the present disclosure.

FIGS. 3A-3D illustrate example mapping tables, according to anembodiment of the present disclosure.

FIG. 4 illustrates an example tree diagram of nodes structured byclassifications, 1^(st) level communities, and 2^(nd) level communities,according to an embodiment of the present disclosure.

FIG. 5 illustrates an example process of assigning unique IDs to nodesof a node graph, according to an embodiment of the present disclosure.

FIG. 6 illustrates an example networked computer system, according to anembodiment of the present disclosure.

FIG. 7 illustrates an example mapping module, according to anembodiment.

FIG. 8 illustrates an example process of mapping users to machines basedon load balancing considerations, according to an embodiment.

FIG. 9 illustrates an example process of routing users to machines,according to an embodiment.

FIG. 10 illustrates an example network diagram of a system forclustering and mapping users within a social networking system,according to an embodiment.

FIG. 11 illustrates an example computer system that may be used toimplement one or more of the embodiments described herein, according toan embodiment.

The figures depict various embodiments of the present invention forpurposes of illustration only, wherein the figures use like referencenumerals to identify like elements. One skilled in the art will readilyrecognize from the following discussion that alternative embodiments ofthe structures and methods illustrated in the figures may be employedwithout departing from the principles of the invention described herein.

DETAILED DESCRIPTION

Node graphs, such as social graphs, may include an extremely largenumber of nodes and connections (or edges) between the nodes. The numberof nodes, for example, may be in the hundreds of millions or evenbillions. In many cases, such as with social networking systemsimplemented by a networked computer system, users are able to access andshare vast amounts of information with other users. The storing andproviding of such vast amounts of data present many challenges. Thesechallenges may include, for example, the significant computational andmemory requirements that are involved in determining how to partitionthe node graph over a distributed system. For example, performing aquery (or request) over the distributed system may potentially require aquery to a large number of machines. This “fanout” of queries may notonly slow down the query response time, but also may place excessivestrain on the network.

The partitioning of the node graph information across the distributedsystem can have a great impact on the computational speed of and strainon a network. For example, where user information is stored (e.g., whichmachine) and how the user information is accessed or stored (e.g., inpersistent memory or fast memory) may significantly impact the amountand speed of computations. Embodiments of the systems and methodsdescribed herein relate to generation of unique IDs which may be used topartition a node graph across a distributed system in an optimal manner.For example, the unique IDs may be generated in a manner that clustersnodes based on their relationships, and increases the tendency of theseclusters to be local to the same machine.

Computational and network performance may be affected by the amount oftraffic that the machines receive. Usage patterns may vary the amountsof load put on machines. Embodiments of the systems and methodsdescribed herein also relate to managing and balancing such load acrossmachines. This may include, for example, determining usage patternsrelated to clusters and their corresponding effects on loads ofmachines, and then reallocating clusters to machines in a manner tobetter balance load.

FIG. 1 illustrates an example clustering module 100, according to anembodiment. The clustering module 100 includes identification module 102and mapping module 104. The clustering module 100 may be implemented aspart of a distributed system of networked computers, such as part of asocial networking system. The components shown in this figure and allfigures herein are exemplary only, and other implementations may includeadditional, fewer, or different components. Some components may not beshown so as not to obscure relevant details.

The identification module 102 may generate unique identifiers (IDs) tobe assigned to nodes of a node graph. In an embodiment, the nodes may beassociated with users of a social networking system. In an embodiment,the nodes may be associated with, for example, persons, non-persons,organizations, content (e.g., images, video, audio, etc.), events, webpages, communications, objects, concepts, or any other thing, notion, orconstruct, whether concrete or abstract, that can be represented as anode. The unique IDs may be generated by first determining aclassification for each node. In an embodiment, the determination of aclassification may be based on any attribute (or attributes). Forexample, the attribute may relate to geographic location (e.g., city ofresidence). In an embodiment, the determination of a classification isnot based on edge weights between nodes, as described in more detailherein.

The classifications, in turn, may be grouped into a higher levelcommunities based on edge weights defined between classifications. Incertain embodiments, the edge weights may be based on a number ofconnections between classifications, the strengths of connectionsbetween the classifications, or a combination of these or other factors.Resulting communities may be iteratively grouped again into still higherlevel communities. These groupings into still higher level communitiesalso may be based on edge weights between communities. The nodes maythen be sorted by classifications and all levels of communities, andsubsequently assigned unique IDs in a numerically sequential manner, asdiscussed in more detail herein.

In an embodiment, connections may represent any types of activities,interactions, common interests, or other shared characteristics betweenclassifications and communities. The edge weights may account for sharedcharacteristics differently. For example, a first type of sharedcharacteristic may reflect a stronger relationship between twoclassifications or communities than a second type of sharedcharacteristic. Therefore, based on their relative importance, the firsttype of shared characteristic may be weighted more heavily than thesecond type of shared characteristic. Accordingly, edge weights mayreflect the relative importance of various types of sharedcharacteristics. The value associated with shared characteristics can berepresented by coefficients, as discussed in more detail herein.

The mapping module 104 may utilize the set of unique IDs for all nodes(also referred to as the “unique ID space”) to partition the node graphover a networked computer system. In an embodiment, the unique ID spacemay be used to map nodes onto database servers of a networked computersystem. In another embodiment, the unique ID space may be used to mapnodes onto cache systems of a networked computer system.

The mapping module 104 may divide (or segment) the unique ID space bythe number of partitions and route nodes to machines of the networkedcomputer system based on the divisions. In an embodiment, thesedivisions may be equally weighted in certain instances to have the samenumber of unique IDs per division. In another embodiment, the divisionsmay not be equally weighted. The mapping module 104 may map nodes tomachines based on their associated unique IDs, which results in atendency of closely connected nodes (e.g., users and their friends) tobe clustered on the same machine (or closely associated group ofmachines, such as a machine pool for instance). In an embodiment, themapping module 104 takes into account load balancing considerations tomap nodes to optimize the load on machines.

FIG. 2 illustrates an example identification module 102, according to anembodiment. The identification module 102 may define a new graph ofclassifications (e.g., geographic location) instead of the originalnodes. The identification module 102 may include classificationdetermination module 202, community generation module 204, and IDassignment module 206. The classification determination module 202 mayidentify an attribute related to the nodes of a node graph, and maydetermine a classification for each node based on the attribute. Anattribute may be any feature or concept according to which the nodes maybe grouped. In an embodiment, more than one attribute and differentcombinations of attributes may be selected and used to classify nodes.

In an embodiment, an attribute may be a geographic association, such asan associated city, neighborhood, county, or other geographic location.Each node may be classified by its geographic association. For example,a social graph may include users as nodes and friendships as connections(or edges) between the nodes. An attribute of the users may be anassociated city (e.g., city of residence). In such case, each user maybe classified based on the city that is associated with the user. Theusers classified based on a city or other association may constitute acommunity of users.

Attributes that correlate strongly with connections between nodes mayfacilitate determination of communities. For instance, in the example ofa social graph, geographic association may correlate strongly withfriendships since people often tend to live, work, and socialize withina geographic area (e.g., city) and thus have a tendency to be friendswith others in the same geographic area. Accordingly, the friends in acommon geographic area may form a community, as described in more detailherein. As another example, any one or a number of demographicconsiderations (e.g., age, ethnicity, gender, religion, etc.) may beattributes that often correlate strongly with connections between nodes.In this regard, persons having similar demographic profiles are oftenfriends. Accordingly, demographic considerations may be used to classifypersons in the determination of communities. The classification of usersin the determination of communities may be based on attributes otherthan those expressly described herein as examples.

The example regarding a social graph is used to provide exemplarycontext and to illustrate operative principles of various embodiments.Discussion of this example of a social graph should not be viewed aslimiting. The underlying principles and concepts of this exampleregarding the social graph may be applicable to other types of graphs,nodes, connections, attributes, etc. in other embodiments.

The classification determination module 202 may represent theclassifications (e.g., cities) as nodes of a new graph, and define edgeweights (or values) between classifications. In certain embodiments, theedge weights may be based on a number of connections betweenclassifications, the strength or type of connection betweenclassifications, or a combination of these or other factors. In anembodiment, edge weights may be determined based on the total number ofconnections between classifications. For example, the edge weight may beproportional to the number of connections between any twoclassifications, such that that the more connections between twoclassifications, the larger the edge weight that represents theirconnections. For instance, the edge weight may be represented by thenumber of connections between the two classifications—e.g., 100connections resulting in an edge weight of 100, 200 connectionsresulting in an edge weight of 200, etc. Other techniques to assignvalues to edge weights between classifications may be used in otherembodiments.

In an embodiment, the edge weights may be determined based on strengthsor quality of the connections (or affinity) between classifications. Forexample, individual connections between two classifications may havevarying coefficients that are assigned based on strengths of theconnections. For example, connections with trait “A” (e.g., two usersare married) may be viewed as stronger (or more important) connectionsthan connections with trait “B” (e.g., two users are colleagues).Accordingly, connections with trait “A” may be assigned a largercoefficient than connections with trait “B”. For example, in the exampleof a social graph, a user in San Jose may have a certain number offriendships with ordinary acquaintances in San Francisco, but have anequal number of friendships with family members, close friends, orfriends with whom the user is in frequent communication, in Los Angeles.The friendships in Los Angeles with family members, close friends, orfriends with whom the user is in frequent communication may be assignedlarger coefficient values than the friendships in San Francisco toreflect the stronger friendships in Los Angeles.

In general, the social graph data may include information aboutcoefficients as measures of relatedness between nodes in the socialgraph. Coefficients may reflect weights for connections (or paths)between nodes in the social graph. For example, coefficients mayindicate that a user is closer to her best friend than to another personbefriended by the user based on the respective weights of the paths thatconnect them. Coefficients may be based on a variety of possibleinteractions between nodes, whether internal or external to the socialnetworking system. Nodes may include users, people, pages, or any objectin the social graph. The determination of coefficients may bedirectional, and depend on many factors, such as the relationship,interaction, or closeness between nodes in the social graph. As anexample, the measure of relatedness of one user (e.g., User A) toanother user (e.g., User B) may be based on various considerationsincluding but not limited to whether: User A is friends with User B;User A commented on a photo of User B; User A liked content or a statusupdate of User B; User A posted on the wall of User B; User A was on thesame thread as User B; User A appears in the same photo as User B; acertain amount of time (e.g., days) transpires with (or without) User Aengaging with User B or content of User B; User A linked to a comment ofUser B; User A shared content of User B with others; User A mentionedUser B in a wall comment; User A viewed profile or other web page ofUser B; etc.

In the foregoing example concerning the determination of User A'scoefficient for User B, many of the possible interactions informing thecoefficient are based on actions of User A. However, other interactionsinvolving actions of User B may also be considered in the determinationof User A's coefficient for User B. Such interactions may include anyvariety of activities, such as whether: User B viewed a photo of User A;User B viewed an album of User A; a certain amount of time (e.g., days)transpires with (or without) User B engaging with User A or content ofUser A, etc. Further, the interactions that inform the determination ofcoefficients may be based on the time duration over which theinteractions occurred (e.g., the last 30 days, 60 days, 90 days, or anyother suitable time interval). Coefficients may also be based on afrequency of interaction within those historical time durations as wellas other factors.

Coefficients may also be asymmetric in some instances. For example, forcertain reasons (e.g., privacy), coefficient scores may be based solelyon the acting user's actions. In an embodiment, a two-way coefficientscore may be computed such that cache sharding better reflects usagepatterns.

The community generation module 204 may group the classifications withincommunities at a first level based on the edge weights betweenclassifications. In an embodiment, a community detection algorithm maybe performed with the classifications as inputs, resulting inclassifications (e.g., cities) being mapped to correspondingcommunities. For example, in an embodiment, classifications having edgeweights with relatively large values between them may be groupedtogether in a community so as to maximize the number of connections orthe strength of connections within a community and to minimize thenumber of connections or the strength of connections betweencommunities.

Communities resulting from grouping classifications at the first levelmay be referred to as first level communities. Iterative groupings maybe performed to generate communities at higher levels. For example, acommunity detection algorithm may be performed with first levelcommunities as inputs to group first level communities to a higher levelof second level communities. Similarly, a community detection algorithmmay be performed with the second level communities as inputs to groupsecond level communities to a higher level of third level communities,and so on. This technique results in classifications being grouped tofirst level communities, the first level communities being grouped tosecond level communities, the second level communities being grouped tothird level communities, and the third level communities being groupedto yet still other higher level of communities. A community in eachsuccessive level of communities may be determined by maximizing thenumber of connections or the strength of connections within thecommunity and by minimizing the number of connections or the strength ofconnections with other communities.

The iterative groupings to generate successive levels of communities arenot limited in number. In an embodiment, the technique may involvemapping to n community levels, where n may be any integer value selectedfor optimal grouping of the classifications and communities. Forexample, the value of n may be two, three, or other suitable number. Asanother example, the value of n may be a value other than two or three.

In the example of a social graph, cities may be grouped into communitiesbased on the edge weights between the cities (e.g., number offriendships between cities, the strength of the friendships betweencities, both, etc.). The resulting first level communities may befurther grouped into second level communities in a similar manner. Theresulting second level communities may be further grouped into thirdlevel communities in a similar manner, and so on. Any number ofiterative groupings of into higher level communities may be performed.In certain embodiments, preexisting IDs (e.g., user IDs) associated withthe original nodes may be mapped to classifications and the variouslevels of communities.

Classifying nodes by attribute and then using the classifications as aworking set by which to group the nodes into communities may providesignificant advantages. In the example of a social graph, a working setbased on nodes associated with over one billion users can be reduced toa working set based on classifications of 750,000 cities associated withthe users. Such reduction in the working set may significantly reducecomputation times for determining the unique IDs from, for example, manyhours to a few minutes. Furthermore, the reduced working set maysignificantly decrease the number of iterative groupings needed forvarious applications. In some instances, the number of iterativegroupings based on the reduced working set to achieve optimal clusteringof nodes may be five iterations or less.

In the example of a social graph, the social graph may includeapproximately one billion nodes, which may be classified with respect toapproximately 750,000 cities. When the cities are grouped based on theedge weights (e.g., number of connections) between the cities, thenumber of resulting first level communities may be approximately 2,000.If the first level communities are further grouped based on the edgeweights between them, the number of resulting second level communitiesmay be approximately 60. Subsequent attempts to group communities ateven higher levels may not provide significant reductions in the numberof communities.

While resulting communities at various levels may have some degree ofcorrespondence with geographic area, they may be based on friendships,which may have a strong correlation to geography. The correspondencebetween communities and geographic area need not be a strictcorrespondence. For example, some geographic areas that are close to oneanother may not have many or strong friendships between them, and somegeographic areas that are distant from one another may have many orstrong friendships. The correlation between geographic area andfriendships may be based on a wide range of considerations, such ascultural factors, demographic trends, common interests or ties, etc.

The ID assignment module 206 may assign unique IDs to a sorted list ofnodes in a numerically sequential manner. The nodes may be sorted in amanner such that friends tend to be clustered together, and tend to havethe same classifications and fall within the same communities. The IDassignment module 206 may sort the nodes by classifications andresulting communities. In an embodiment, the nodes may be sorted byclassification, and then by first level community, and then again bysecond level community, and so on.

The unique IDs may be a numerical sequence (e.g., from one to 1 billion)that is assigned to the sorted list of nodes. In general, clusterednodes or communities at various levels will have unique IDs that arenumerically proximate to one another. For example, nodes with the sameclassification will have unique IDs that are numerically proximate toeach other. As another example, nodes within the same first levelcommunity will have unique IDs that are numerically proximate to eachother. Nodes within the same second level community will have unique IDsthat are numerically proximate to each other. Nodes within the samethird level community will have unique IDs that are numericallyproximate to each other. It should be appreciated that the term“numerically proximate” is used broadly herein and is not limited tounique IDs having a strict sequence of successive numbers includingevery integer or value from the beginning to the end of a sequence. Forexample, numerically proximate unique IDs may be numerically sequentialodd numbers—e.g., 1, 3, 5, 7, 9, and so on. As another example,numerically proximate numbers may be a series of non-successive odd andeven numbers—e.g., 1, 2, 4, 5, 7, 8, and so on. As yet another example,numerically proximate numbers may indicate that the difference betweenvalues in a set of unique IDs for the nodes, as determined by thetechniques described herein, is relatively smaller than the differencebetween values in a set of another type of preexisting IDs for thenodes.

The unique ID space may thus be structured such that friends,classifications, and communities have unique IDs that are proximate toone another. The unique IDs may be divided for mapping across anetworked computer system. When the unique ID space is divided, thedivisions of the unique ID space will include clusters of friends, aswell as clusters of cities and communities at various levels. In someembodiments, a city or other community at a particular level may besplit between partitions. In general, partitioning may improve localityand optimize system performance while reducing disadvantages associatedwith fan out, as discussed in more detail herein.

The identification module 102 may update definitions of the new graph.The definition of a new graph based on classifications instead of theoriginal nodes by the identification module 102 may require fewerupdates. In the example of a social graph, the number of friendships orstrength of friendships between cities may be fairly static and may notchange significantly over short periods of time. In contrast, changes tousers may occur more frequently since people may, within a city, move,make new friends, etc. Thus, because the new graph is based onclassifications instead of the original nodes, the identification module102 may be required to perform relatively fewer updates to account forchanges in the underlying data associated with users. In variousembodiments, the identification module 102 may update the new graph atvarious intervals (e.g., every week, month, 3 months, 6 months, or otherapplicable time period) or upon the occurrence of certain events (e.g.,a threshold change in the edge weights between cities or communities).

FIGS. 3A-3D illustrate an example mapping table, according to anembodiment. The example mapping table is described with respect to asocial graph. However, underlying concepts discussed in connection withthe table are not limited to any single social graph or its particularfeatures.

In FIG. 3A, the table 300 includes a column USER that lists 12 users(e.g., nodes). For the sake of clarity and brevity, only 12 users areshown for exemplary purposes. It should be appreciated that the mappingtable generated may include millions, billions, or any number of users.In an embodiment, the column USER may represent a preexisting ID (e.g.,user ID) previously assigned for each user, which may then beaccordingly mapped to the classifications (e.g., cities) in column L1and communities in columns C1 and C2.

Column L1 represents the associated cities of the users. The cities mayrepresent the residences of the users. For example, each of the users1-12 is shown next to its associated cities—e.g., either New York (NY),San Francisco (SF), San Diego (SD), Los Angeles (LA), or New Jersey(NJ).

Column C1 represents 1^(st) (first) level communities that result fromgrouping the cities based on edge weights defined between the cities(e.g., based on the number of friendships between cities, strengths ofthe friendships between cities, etc.). In an embodiment, the 1^(st)level communities are selected such that cities having a large number(or strength) of friendships between them are grouped together so as tomaximize the number (or strength) of friendships within 1^(st) levelcommunities and to minimize the number (or strength) of friendshipsbetween 1^(st) level communities. As shown, NY is listed as within1^(st) level community “1”; SF is listed as within 1^(st) levelcommunity “2”; SD and LA are listed as within 1^(st) level community“3”; and NJ is listed as within 1^(st) level community “4”. In theembodiment shown, LA and SD may have a relatively large number offriendships between them, resulting in LA and SD being grouped withinthe same 1^(st) level community.

Column C2 represents 2^(nd) level communities that result from groupingthe 1^(st) level communities based on edge weights defined between the1^(st) level communities (e.g., based on the number of friendshipsbetween 1^(st) level communities, strengths of the friendships between1^(st) level communities, etc.). In an embodiment, the 2^(nd) levelcommunities are selected such that 1^(st) level communities having alarge number (or strength) of friendships between them are groupedtogether so as to maximize the number (or strength) of friendshipswithin 2^(nd) level communities and to minimize the number (or strength)of friendships between 2^(nd) level communities. In the embodimentshown, NY and NJ fall within the same 2^(nd) level community “1”; andSF, SD, and LA fall within the same 2^(nd) level community “2”.

The cities and resulting levels of communities may then be sorted,resulting in a sorted list of users (or user IDs) based on cities andresulting levels of communities. For example, the users within themapping table 300 may be sorted by cities (column L1), 1^(st) levelcommunities (column C1), and 2^(nd) level communities (column C2). Sincecommunities were grouped based on edge weights associated withfriendships, friends are, or have a tendency to be, clustered together.

FIG. 3B shows the mapping table 300 after the users have been sorted bycities (column L1). As shown, users for LA are listed first at the topof the chart, followed by cities NJ, NY, SD, and then SF.

FIG. 3C shows the mapping table 300 after the users have been sorted by1^(st) level community (column C1). As shown, users in 1^(st) levelcommunity “1” are listed first at the top of the chart 200, followed byusers in 1^(st) level communities “2”, “3”, and then “4”.

FIG. 3D shows the mapping table 300 after the users have been sortedbased on 2^(nd) level communities (column C2). As shown, users in 2^(nd)level community “1” are listed first at the top of the chart 200,followed by users in 2^(nd) level community “2”.

As a result of the sorting procedure, the users 1-12 are sorted by city,1^(st) level communities, and 2^(nd) level communities. For example, allusers within the 2^(nd) level community “2” are numerically proximate toeach other (e.g., users 2, 6, 8, 11, 4, 7, 1, 3, and 12). Furthermore,within the 2^(nd) level community “2”, all users within the 1^(st) levelcommunity “2” are numerically proximate to each other (e.g., users 2, 6,8, and 11), and all users within the 1^(st) level community “3” areproximate to each other (e.g., users 4, 7, 1, 3, and 12). Still further,within 1^(st) level community “2”, all users within the city “SF” areproximate to each other (e.g., users 2, 6, 8, and 11). Within 1^(st)level community “3”, all users within the city “LA” are proximate toeach other (e.g., users 4 and 7), all users within the city “NY” areproximate to each other (e.g., user 1), and all users within the city“SD” are proximate to each other (e.g., users 3 and 12). This samepattern also applies to all users within 2^(nd) level community “1”.

In this way, when the identification module 102 assigns unique IDs in anumerically sequential manner to the sorted list of users, users withinthe same city and resulting levels of communities will have unique IDsthat are numerically proximate one another. For example, the table 300in FIG. 3D includes a column UQ_ID that lists a unique ID that has beenassigned in a numerically sequential manner to users that have beensorted by classifications, 1^(st) level communities, and 2^(nd) levelcommunities. As shown, users having the same classification or fallingwithin the same community are proximate to one another, and accordinglyhave unique IDs that are numerically proximate to one another. Uniquelyidentifying nodes in this manner may prove beneficial or advantageousfrom the perspective of improving system performance and optimizingcomputing resources, as described herein. It should be appreciated thatwhile communities may have a geographical component in some instances,in other instances communities may not have a geographical component. InFIG. 3A-3D, for example, user 1 and user 5 are both associated with NYbut are within different 1^(st) level communities. User 1 may, forinstance, have a large number of friends in 1^(st) level community “3”and is then grouped within 1^(st) level community “3”. On the otherhand, user 5 may have a large number of friends in 1^(st) levelcommunity “1” and is then grouped within 1^(st) level community “1”.

In some embodiments, sorting techniques may differ. For example, insteadof sorting on classifications and every level of communities, the usersmay be selectively sorted based on any combination of the classificationor levels of communities. For example, the users may be sorted based ononly the highest level community (e.g., the 2^(nd) level community).Then, unique IDs may be assigned based on such sorting. As anotherexample, only the two highest level communities (e.g., the 1^(st) levelcommunity and the 2^(nd) level community) may be sorted before uniqueIDs are assigned.

FIG. 4 illustrates an example tree diagram 400 of nodes 401 assigned toclassifications 402, 1^(st) level communities 403, and 2^(nd) levelcommunities 404, according to an embodiment. The tree diagram 400 mayinclude any suitable number, x₁, of nodes. In the example shown, onebillion nodes 401 are grouped by the classifications 402, as representedby the lines from each node 401 to a corresponding classification 402.Any suitable number, x₂, of classifications associated with the nodesmay be determined. In the example shown, 750,000 classifications 402representing geographic locations (e.g., cities) are associated with thenodes 401. Each of the classifications 402 is grouped within 1^(st)level communities 403, as represented by the lines from eachclassification to a corresponding 1^(st) level community. Any suitablenumber, x₃, of 1^(st) level communities 403 may be determined. In theexample shown, 2,000 1^(st) level communities 403 are associated withthe classifications 402. Furthermore, each of the 1^(st) levelcommunities 403 are grouped within 2^(nd) level communities 404, asrepresented by the lines from each 1^(st) level community to acorresponding 2nd level community. Any suitable number, x₄, of 2^(nd)level communities may be determined. In the example shown, 60 2^(nd)level communities 404 are associated with the 1^(st) level communities403. The tree diagram 400 is structured such that nodes 401 having thesame classification and falling within the same communities areclustered together, and are thus structured in a sorted manner based onthe classifications 402, the 1^(st) level communities 403, and the2^(nd) level communities 404. In this way, unique IDs may be assigned tonodes 401 in a numerically sequential manner from beginning to end(e.g., from left to right). Nodes having the same classification orfalling within the same community will have unique IDs that arenumerically proximate to one another. It should be appreciated that thevalues shown for x₁, x₂, x₃, and x₄ in FIG. 4 are exemplary. Anysuitable number may be implemented in different embodiments.

FIG. 5 illustrates an example process of assigning unique IDs to nodesof a node graph, according to an embodiment. It should be appreciatedthat the discussion above for FIGS. 1-4 may also apply to the processfor FIG. 5. For the sake of brevity and clarity, every feature andfunction applicable to FIG. 5 is not repeated here.

At block 502, nodes in a node graph may be identified. In an embodiment,for example, the nodes may be associated with users within a socialgraph. At block 504, one or more attributes for the nodes may beidentified. The attributes may relate to the nodes, or connectionbetween nodes. At block 506, classifications for each node may begenerated based on the attribute. In one embodiment, the attribute maybe a geographic association (e.g., association with a city), and thenodes may be classified by the geographic location they are associatedwith (e.g., city of residence, city of business or operation, etc.). Theclassifications may be viewed as nodes of a new graph, having edgeweights defined between classifications. In an embodiment, the edgeweights may be based on the number of connections between nodes. In anembodiment, the edge weights may be based on strengths of theconnections, which may be represented by coefficients. In an embodiment,blocks 502, 504, and 506 may be performed by the classificationdetermination module 202 of FIG. 2.

At block 508, the classifications (e.g., associated cities) may begrouped into communities based on the edge weights defined between theclassifications (e.g., based on the number or strength of connectionsbetween classifications). The grouping may provide a map fromclassifications to 1^(st) level communities. At block 510, it isdetermined if an additional grouping into another level of communitiesis to be performed. If an additional grouping is to be performed, the1^(st) level communities that resulted from block 508 are grouped basedon the edge weights between the 1^(st) level communities (e.g., based onthe number of connections between 1^(st) level communities or thestrength of the connections between 1^(st) level communities), asrepresented by the arrow from block 510 to block 508. This process maybe repeated in a similar manner for any additional groupings into higherlevel communities. If no additional groupings into higher levelcommunities are to be performed, then, at block 512, the nodes (fromblock 502) are sorted based on a sorting of the classifications andresulting levels of communities. The nodes are sorted in a manner suchthat friends tend to be clustered together in the sorted list, andfurther tend to have the same classifications and fall within the samecommunities.

At block 514, unique IDs are assigned to the sorted list of nodes in anumerically sequential manner. In this way, nodes (e.g., users) havingconnections (e.g., friendships) will tend to be clustered together withthe same classification and within the same communities, and accordinglyhave unique IDs that are numerically proximate to one another. In anembodiment, blocks 508 and 510 may be performed by the communitygeneration module 204 of FIG. 2. Furthermore, in an embodiment, blocks512 and 514 may be performed by the ID assignment module 206 of FIG. 2.

The classification and higher levels of communities may not necessarilyprovide finer grain information within classifications. For example, asorted list of users may not necessarily be sorted such thatsub-communities of friends within a city are sequentially proximate toone another in the unique ID space. A sub-community of a city may, forinstance, be associated with a suburb having a high number ofconnections between users.

In an embodiment, sub-communities of nodes may be identified within aclassification. For example, a classification for a sub-community may bederived in a similar manner as discussed herein. Nodes may then begrouped into sub-communities within the classification based on, forexample, the number or strength of connections between nodes. Additionallevels of sub-communities may also be iteratively computed. A sortedlist of nodes may then be generated by sorting the nodes byclassifications and sub-communities (and higher level communities). Theunique IDs may then be assigned in a numerically sequential manner tothe sorted list of nodes. In this way, sub-communities of nodes havingconnections will tend to be clustered together.

Uniquely identifying nodes based on the techniques performed byidentification module 102 may provide advantages in various situations.For example, generating and assigning unique IDs by identificationmodule 102 may improve the manner in which information may be compressedfor storage. Networked computer systems may include main memory that maybe slow to access but have large storage capacities. For this reason,compression may not be an important consideration with respect to mainmemory management. However, memory hierarchies of networked computersystems also often implement faster memory that may be accessed moreoften to enhance performance speed. Because the faster memorytechnologies tend to be more expensive, the size of the memory is oftenlimited and thus compression techniques play a more important role tomaximize the amount of data that can be stored therein. Delta encodingis one compression technique that may benefit from the unique ID spacegenerated and assigned by the identification module 102.

For example, a user's friend list may include preexisting user IDs: 200;3,000; and 30,000. Generally, to delta encode the friend list, thefriends' user IDs are sorted from smallest to largest value. A precedinguser ID value may be subtracted from each user ID, except the smallestuser ID, which does not have a preceding user ID. The delta encoded listmay include the following: 200; 2800; and 27,000. The value 2800 wasderived by subtracting 200 from 3000, and the value 27,000 was derivedby subtracting 3,000 from 30,000. By delta encoding, the idea is togenerate smaller numbers which require less bits to store. However, asshown, when dealing with a large set of potential user ID values, thedifferences between user ID values may be relatively large values.

Because the unique IDs are assigned in a numerically sequential mannerto a sorted list of nodes (e.g., users) that cluster the nodes based onconnections, many nodes (e.g., users) that have connections (e.g.,friendships) will be clustered together within the sorted list, andultimately assigned unique IDs that are sequentially proximate to oneanother. Therefore, the same friends with user IDs 200; 3,000; and30,000 may have unique IDs assigned by identification module 102 thatsequentially proximate to one another, such as: 1,001; 1,003; and 1010.Applying delta encoding to these unique IDs results in the deltaencoding values: 1,001; 2; and 7. These delta encoded values providesignificantly smaller values, which require significantly less data tostore in memory.

Generating and assigning unique IDs to nodes based on the techniquesperformed by the identification module 102 may prove beneficial whenpartitioning a massive graph at scale across networked computer systems,including disks, machines, database servers, and data centers.

FIG. 6 illustrates an example networked computer system 600, accordingto an embodiment. The networked computer system 600 includes n databaseservers 602, n cache systems 604 associated with the database servers602, web server 606, and cache system 608 associated with web server606, where n is any number of database servers and associated cachesystems to support the computer networked system 600, such as a socialnetworking system. The database servers 602 include database server 612,database server 614, database server 616, and database server 618. Thecache systems 604 include cache system 622, cache system 624, cachesystem 626, and cache system 628. The database server 612 is associatedwith the cache system 622; the database server 614 is associated withthe cache system 624; the database server 616 is associated with thecache system 626; and the database server 618 is associated with thecache system 628. The database servers 602, the cache systems 604, andthe web server 606 may be communicatively coupled to one another throughone or more networks, such as a LAN, WAN, and the internet. Each of thedatabase servers 602 may represent a single database server or a datacenter. Information for the graph, such as a social graph, may be storedwithin a persistent memory layer formed by the database servers 602.

In the example of a social graph, the database servers 602 may includeuser information for all of the users in the social graph. The userinformation may include, for example, information related to a userprofile, images, videos, posts, status updates, friends lists, feeds, orany other information associated with the user and the activities of theuser on a social networking system supported by the social graph. Userinformation for a specific user may be stored on a specific databaseserver of the database servers 602. Users may be mapped to one of thedatabase servers 602 irrespective of any of the user's friendships. Forinstance, new users of a social networking system may be allocated toone of the database servers 602 based on which of the database servers602 has capacity to maintain data about the user at the time the userjoined the social networking system.

In certain embodiments, a user ID associated with a user may be used toindicate which of the database servers 602 a user's information is to bestored on. If user information is desired for a given user, then thespecific database server with the user's information may be queried toobtain the user's information. For example, when user A accesses the webserver 606 of the networked computer system 600, the web server 606 mayidentify the user ID for user A, and may use the user ID to determinethat the user information for user A is stored on the database server614. The user information for user A may include, for example, a friendlist of user A's friends or other information about user A.

User information for each of user A's friends may then be obtained byquerying each database server having user information for a respectivefriend, as represented by queries 632, 636, and 638 to the respectivedatabase servers 612, 616, and 618. The queries 632, 636, and 638 toeach of the respective database servers 612, 616, and 618 representfanout queries. While the example shows three additional queries 632,636, and 638 to respective database servers 612, 616, and 618, user Amay have a significantly larger number of friends (e.g., hundreds orthousands of friends) spread out over many of the database servers 602,which could potentially require a fanout query to a different databaseserver for each friend. In this circumstance, the large number of fanoutqueries would be undesirable. Fanout queries may significantly decreaseperformance (e.g., speed with which information is obtained) andgenerate excessive amounts of network traffic, especially when dealingwith extremely large number of nodes and queries. The problemsassociated with fanout queries are further compounded when queries foruser information for “friends of friends” of (or for indirect friendshaving still larger degrees of separation from) user A are performed.Fanout queries may also contribute to excessive use of memory in thecache systems 604.

The networked computer system 600 also includes the cache systems 604implemented in association with the database servers 602 to providefaster memory access than the persistent memory layer of databaseservers 602. For example, the cache systems 604 may implement cachelayer services within RAM or other form of fast memory technology, suchas Flash memory. For instance, data or computations may be cached usingAlternative PHP Cache (APC), Memcache, etc. Similarly, web server 606may also cache data or computations within cache system 608. When aquery for user information for user A is first sent to a given databaseserver 614, for example, the user information may be retrieved from thedatabase server 614 and also stored in the cache system 624. Thereafter,as long as the user information for user A remains in the cache system624, subsequent queries for user information for user A may be morequickly retrieved from the cache system 624. However, if userinformation for user A's friends are stored on different databaseservers 602, then the cache systems 604 may not necessarily providesignificant reductions to the number of fanout queries.

Since friends tend to be part of one or more groups of friends, there isstrong tendency for friends to have many friends in common. Whencollecting user information for friends, and friends of friends, manyqueries for user information of common friends may occur. If thesefriends are randomly scattered over different database servers and cachesystems, then the fanout queries will be performed.

In certain embodiments, the cache systems 604 may be configured tocluster friends within the same cache system, thus increasing cachelocality. Increasing the number of friends who are local to a commoncache system may increase the likelihood that requested user informationfor common friends will already be cached by a previous query for theuser information. Increasing the cache hit rate in this manner reducesfanout queries even if the user information for common friends is storedin different database servers 602. Therefore, increasing cache localityand cache hit rate may produce significant benefits in performance,reduction in network traffic, etc., especially when dealing withextremely large numbers of nodes and queries.

FIG. 7 illustrates a mapping module, according to an embodiment. Themapping module 104 is shown including partitioning module 702, routingmodule 704, load monitoring module 706, and temporal balancing module708. The partitioning module 702 may determine the number of partitionsinto which the graph is to be partitioned. The number of partitions mayrelate to the number of physical machines (e.g., database servers 602 orcache systems 604) across which the graph data is to be distributed. Theunique ID space may then be divided (or segmented) based on the numberof nodes for each partition.

For example, if a social graph of 1 billion users, represented by nodes,is to be partitioned over 100 cache systems, then the number of users(e.g., 1 billion) may be divided by the number of partitions (e.g., 100)to provide a partition size—i.e., the number of users per partition(e.g., 10 million users per partition). Accordingly, the unique ID spacemay be divided by the partition size, resulting in 10 million unique IDsper partition. Since the unique ID space is numerically sequential, the10 million unique IDs in each partition are numerically proximate to oneanother. Therefore, the clustering of cities and communities within theunique ID space are reflected in the partitioning of the social graphover a multitude of machines. Furthermore, the tendency of friends to beclustered in the unique ID space is reflected in the partitioning of thegraph to the machines. In this example, the partition sizes are equal(e.g., 10 million users per partition), resulting in the same number ofunique IDs on each of the machines. In another embodiment, the partitionsizes may not be equal, resulting in varying numbers of unique IDs onthe machines.

The routing module 704 may map users to machines based on the divisionsof the unique ID space and the partitions—e.g., as described for thepartitioning module 702. The routing module 704 may then route users tomachines according to the mapping. For example, in some instances, thenumber of partitions (e.g., machines) for an application will be known,and the unique ID space may be divided, as described, to map users tothe cache layer of a machine. The unique ID space may be evenly orunevenly divided in different embodiments. For example, the divisions ofthe unique ID space may result in splitting a city or community betweentwo machines. Furthermore, some levels of communities may be large, andthus not all communities may fit on a single machine. In an embodiment,the partition sizes (e.g., number of users per partition) may beadjusted accordingly to maintain integrity in the localities of citiesor communities.

The unique ID space may be used to map users to cache systems. Theunique IDs may enable clusters of friends to be routed to the same cachesystem, which may significantly improve locality and thus providebenefits in the processing (or executing) of queries provided to thenetworked computer system. The queries may be of any type, such as“friends of friends” queries submitted to a social networking system.Queries may be directed to appropriate cache systems that are needed toexecute the queries. For example, a query for User A's friends would besent to the machine that User A is mapped to based on the unique ID ofUser A.

In certain instances, preexisting IDs (e.g., user IDs) may already beallocated to nodes and used to map users to database servers, but in amanner that does not account for edge weights or desired clustering ofclosely connected nodes. In such case, unique IDs may constitute analternative identifier. The user IDs may be mapped to the unique IDs,and the unique IDs may be used to map the users to cache systems. Inthis way, user data in the persistent memory layer (e.g., databaseservers) may be maintained, while the benefits of the unique ID spaceare realized in a cache layer (e.g., cache systems). In one embodiment,the mapping of user IDs to unique IDs may be stored on a machine that isaccessed whenever user IDs are to be converted to unique IDs for cachelayer operations.

Another benefit of the unique IDs described herein is that the number ofpartitions is not required to be known in order to generate the uniqueIDs. For example, if multiple services require different numbers ofpartitions, then the same unique ID space may be divided accordinglybased on the corresponding number of partitions. For instance, in theexample of a social graph, the networked computer system may include apersistent memory layer (or tier) of database servers and a cache layer(or tier) of cache systems. One cache layer service may be an indexservice implemented over 100 cache systems (e.g., 100 partitions).Another cache layer service may be a newsfeed service implemented over200 cache systems (e.g., 200 partitions). Yet another cache layerservice may be a graph service that is implemented over 300 cachesystems (e.g., 300 partitions). In this way, the persistent memory layermay be kept fairly static, but the cache layer may be dynamicallyconfigured.

Routing users based on the unique IDs may significantly improve fanoutissues. If users on a machine tend to access similar data, then the datawill be cached after an initial query for the data and available forsubsequent queries that need the same data. Take for instance a “friendsof friends” query. Friends or communities may be clustered onto the samecache system. Therefore, when User A submits a query about her friends,the data for all User A's friends is fetched and stored in cache, if notalready in cache. If User B is friends with User A, then it is likelythat User A and User B have some number of friends in common, especiallyif User A and User B are living in the same city. Thus, when User Bsubmits a query about his friends, any data for common friends of User Aand User B will be already cached from the time when User A submittedher query. The greater number of friends in common, the greater theefficiency that results. Furthermore, when applied over a large numberof users (e.g., 500 million users, a billion users, etc.), tremendousgains in performance and network traffic may be realized.

Furthermore, by routing a user to the same machine over differentqueries, the user may take advantage of data that she has alreadycached. For example, when a user refreshes data, such as a newsfeed orposts on a social networking system, having the query sent to the samemachine in which the previous data is cached may provide a significantimprovement in the speed with which the data is obtained.

While the particular examples described herein may relate to users andtheir friendships, the underlying concepts and principles are applicableto other nodes and connections. As discussed herein, nodes may be of anytype. Furthermore, connections may include various types ofrelationships. For instance, a connection may be a “follow” edge, wherea user follows another entity or user. The same approach of routingnodes to machines based on unique IDs may be expanded to other entitiesand not just persons, for example, to determine that soccer is popularin Egypt, cricket is popular in Bangladesh, and a particular business ispopular in the US. For instance, one query may be “Show me all thepeople who like Business A and live in San Francisco”. The query couldbe executed more efficiently if a web page of Business A associated witha social networking system was on the same machine as many of its fans.In particular, query execution may be enhanced by maintaining the webpage of Business A and its fans in the cache layer of a machine.

While mapping users to machines based on divisions of the unique IDspace improves locality on machines, the loads on each machine may vary,and, in some instances, significantly. In an embodiment, the routingmodule 704 may route users to machines based on load considerations. Theload monitoring module 706 may monitor the loads of the machines whilethe machines are online, and work in conjunction with routing module 704to route users to machines based on load considerations. In anembodiment, the loads may be monitored to determine if they exceed athreshold or drop below a threshold. In some instances, the amount ofload (e.g., percentage of a maximum capacity) on a machine at any giventime is monitored.

In an embodiment, an initial mapping is based on the divisions of theunique ID space, whether evenly distributed or not, and thereafter therouting module 704 may route users dynamically based on load balancingconsiderations. For example, a query by a user may be received alongwith the preexisting user ID for the user. A mapping of preexisting userIDs to the unique ID space may be used to convert the preexisting userID to a unique ID. A shard number may then be determined based on apartition size, both of which may be determined by the example equationsbelow:Partition size=(number of users)/(number of partitions)Shard number=(unique ID)/(partition size)

For example, for 2.25 billion users and 15 thousand partitions, thepartition size would be 150 thousand users per partition. Dividing anysingle unique ID by 150 thousand may then be used to determine acorresponding shard number. The routing module 704 may then map theshard number to the appropriate machine after taking into account loadbalancing considerations identified by the load monitoring module 706.After the shard number is mapped to a machine, the query may be executedon the machine.

In an embodiment, load may be determined in part by tracking the numberof queries a machine has received. For example, as an application isexecuting queries, it may export a counter indicating the number ofqueries each shard is processing (e.g., application shard number 100 has100 queries, application shard number 101 has 500 queries, etc.). Theload monitoring module 706 may then receive the exported counter dataand work in conjunction with the routing module 704 to, for example,determine whether or how to move users between shards of machines. Forexample, the load monitoring module 706 may monitor whether the numberof queries that a machine is processing exceeds a threshold. If thethreshold is exceeded, then the load monitoring module 706 may preventadditional queries from being routed to the machine until the number ofqueries being processed drops below the threshold. These additionalqueries may be routed to another machine until the number of queries themachine is processing drops below the threshold. Likewise, the loadmonitoring module 706 may monitor whether a number of queries that amachine is processing drops below a threshold. If the number of queriesdrops below the threshold, then the load monitoring module 706 maydetermine that this machine is available to receive additional queries,such as the queries prevented from being routed to machines exceeding athreshold of queries.

In one embodiment, the load monitoring module 706 determines if amachine is overloaded, and routes users accordingly. For example, a usermay be initially mapped to a machine that is currently overloaded. Theoverloaded status is detected by the load monitoring module 706 andcommunicated to routing module 704, which routes the user to a differentand less loaded machine. The overloaded machine is thus prevented frombeing further loaded, and the load of the underloaded machine isincreased. In one embodiment, the load monitoring module 706 maydetermine a user needs more than one machine for a query, and therouting module 704 accordingly may route the query to other machines.The movement of users from one shard to another shard based on loadbalancing considerations, such as query processing demands, maycompromise locality to some degree. The load monitoring module 706 maycontinuously weigh the tradeoff between locality and query speed.

In an embodiment, a geographic location may exhibit limited usagepatterns. For example, for some applications, specific users associatedwith certain geographic locations may not be routed to one or moremachines because of, for example, legal reasons, privacy reasons, etc.,creating unused computing resources. For example, a country may not useor permit a particular application to be available to its residents orcitizens. For instance, the European Union and Canada may not allow aspecific application for its citizens, and thus users within thoseborders do not have access to that application. The unused shard in thecache system allotted for the application will be unused by those users.Therefore, other users associated with other geographic locations may berouted to the machine to utilize available computing resources, such asthe unused shard of the cache system.

In one embodiment, the sections of the unique ID space corresponding togeographic locations associated with prohibited applications are removedfrom the unique ID space. A modified unique ID space (without the uniqueIDs corresponding to the blacked out geographic locations) may then bedivided (e.g., evenly or unevenly) based on the number of partitions tomap users to a shard number and corresponding machine.

In certain embodiments, users may be mapped to machines according tousage patterns that are strongly correlated with geographic locations.Different geographic locations may exhibit different usage patterns.While the unique ID space may help to optimize locality, geographiclocations may have varying usage patterns, which may lead to varyingloads on machines during different times. These load swings may varysignificantly by providing large loading on machines at some times andproviding small loading on the same machines at other times.

The temporal balancing module 708 may work in conjunction with therouting module 704 to route users to machines in a manner that accountsfor usage characteristics, such as temporal fluctuations in usagepatterns. For example, loads for geographic locations may vary by timeof day (e.g., work hours versus non-work hours). As another example,loads also may vary by the day (e.g., holiday versus normal day) or byother larger intervals of time (e.g., summer vacation versus basketballchampionship). The temporal balancing module 708 may use data from theload monitoring module 706 to determine usage patterns and, based on theusage patterns, work with the routing module 704 to route users tovarious machines to optimize load balancing.

For instance, the temporal balancing module 708 may identify geographiclocations that have complementary usage patterns. Complementary usagepatterns may refer usage exhibited by geographic locations that is notin phase. For example, one type of complementary usage pattern mayinvolve a first geographic location having a peak in traffic usage when,at a same or overlapping time, a second geographic location has a valleyin traffic usage. Likewise, another type of complementary usage patternmay involve the first geographic location having a valley in trafficusage when, at a same or overlapping time, the second geographiclocation has a peak in traffic usage. Instead of routing the twogeographic locations on two separate machines with significant swings ofhigh traffic and low traffic, the temporal balancing module 708 may pairthem together on the same machine (or cluster of machines). In this way,the machine, in effect, primarily services only one geographic locationduring its corresponding high traffic time, thus optimizing use ofcomputing resources and balancing the load on the machine. In anembodiment, high traffic may be determined based on whether the trafficexceeds a predetermined threshold. Similarly, in an embodiment, lowtraffic may be determined based on whether traffic drops below athreshold.

Within a social networking system, a geographic location (e.g., city,country, community, etc.) or associated shard may exhibit large swingsin the amount of usage of the social networking system during peak timesand non-peak times. This pattern may be generally exhibited, forexample, by different users in a common geographic region or time zone.For example, many cities, regions, and even countries may exhibit lesstraffic during the night, when people tend to be sleeping, than duringthe day. Thus, traffic may be categorized in 12 hour periods of time orother time intervals. As another example, a first geographic locationmay exhibit distinct usage (e.g., heavy traffic or minimal traffic)during an eight hour interval during the day, a second geographiclocation may exhibit distinct usage during a six hour interval duringthe day, a third geographic location may exhibit little or no distinctusage pattern.

Usage patterns may be based on habits or cultures that are associatedwith certain geographic regions. For instance, people in one geographiclocation may predominantly use the social networking system at home.Another geographic location may predominantly use the social networkingsystem at work. Yet another geographic location may predominantly usethe social networking system on weekends or other special days.

Furthermore, users of a social networking system may be unevenlydistributed in different geographic locations. For instance, the UnitedStates and Europe may have very large number of users that exhibitsignificant usage patterns over the same or overlapping time periods.The peak periods of time for these two countries may overlap, generatingtremendous combined usage during the overlapping time period.Accordingly, the combination of users from these geographic locationswould cause excessive swings in load on a machine. Accordingly, in anembodiment, during the time that each geographic location exhibits peakusage, the users associated with one geographic location may be routedby the temporal balancing module 708 to a different machine during thattime to avoid excessive swings in load. The users may be returned to theoriginal machine after the peak usage interval. Routing users to avoidsuch excessive swings in load in this manner may be performed for anynumber of geographic locations over any intervals to optimize loadbalancing. The temporal balancing module 708 may identify intervals oftimes associated with heavy or light usage and accordingly group or bandtogether specific geographic locations onto the same machine to optimizeload. The temporal balancing module 708 may implement any number ofpermutations which may mix and match varying number of geographiclocations and variously sized time intervals to optimize the loadbalance for different usage patterns.

The temporal balancing module 708 may band geographic locations by timezones that are complementary. For example, two geographic locations maycomplement one another in 12 hour periods, three geographic locationsmay complement each other in 8 hour periods, etc. This banding ofgeographic locations may be performed in various combinations forgeographic locations around the world. In some instances, the temporalbalancing module 708 may treat different geographic locations as a unitfor purposes of load balancing.

The temporal balancing module 708 may also take into account thetradeoff between load balancing and locality. For instance, while twogeographic locations may complement one another with respect to usagepatterns, they may not necessarily be routed to the same machine if theimpact to locality is determined to be too great.

Various systems and techniques may be implemented to account forvariations in load. In an embodiment, general purpose pools of machinesmay be implemented to accommodate excessive load demands or a decline inload processing capability, such as due to maintenance. For example, ifa machine is currently overloaded or inoperative due to maintenance,then queries mapped to the machine may be temporarily routed to ageneral purpose pool of machines until the machine is no longeroverloaded or inoperative due to maintenance.

In an embodiment, the size of a machine pool associated with a shard maybe dynamically varied in response to load demands or expected loaddemands. For example, the number of machines allotted to the machinepool may be increased or decreased dynamically to account for higher orlower load demands, respectively. In some instance, the size of themachine pool may vary based on expected time-of-day load changes. Insome instances, the size of the machine pool may vary in response tounexpected load surges, such as load surges due to a community emergencyfor instance.

In some instances, certain users, communities, or chards may induceunexpectedly high loads. For example, a user may be a celebrity orpublic figure that receives sudden nationwide attention, drawing manyqueries to the user's account at the same time. The sudden and excessiveincrease in load demand put on the machine or shard associated with theuser's account may be disruptive. The size of a machine pool associatedwith the user or shard may be dynamically increased to accommodate theincreased load demand. In an embodiment, queries may be routed to ageneral purpose pool of machines to help alleviate the load demand. Insome instances, the queries are routed to the general purpose pool ofmachines until the machine pool associated with the user or shard hasbeen dynamically resized.

In some instances, load demands may be generated by users that are noteffectively linked to a community of users or that do not have anassociated unique ID, such as anonymous users, users without anyfriends, users not logged in, search engine scrapers, etc. Because theseusers are not effectively associated with a community or unique ID, theload demands they generate may not necessarily benefit from, orcontribute to, some of the load and performance benefits describedherein. In an embodiment, queries from such users may be routed to ageneral purpose pool of machines, a dedicated machine pool for thesetypes of non-social users, or load balanced across an entire set ofmachines in a machine pool or in multiple machine pools.

Mappings between users to communities, unique IDs, or to shards may attimes change significantly, such as due to an alteration of theclustering or to the way the node graph is partitioned. To reduce theimpact of deploying a new map with significant changes to the previousmap, updates may be deployed gradually or at times of reduced traffic orload, such as during global off peak hours. In an embodiment, a versionidentifier may be used in conjunction with the unique IDs, identifiersfor communities, or identifiers of shards in order to uniquely identifywhich map is being utilized for a current query.

FIG. 8 illustrates an example process of mapping users to a machinesbased on load balancing considerations, according to an embodiment. Atblock 802, loads and usage times of machines are monitored. Themonitoring may be dynamic—e.g., determined as queries are received. Forexample, if a query is received and initially mapped to a machine (orplurality of closely associated machines, such as a machine pool), thecurrent load on the machine may be monitored first to determine if it isoverloaded. In another example, the usage patterns of geographiclocations are monitored. In an embodiment, block 802 may be performed bythe load monitoring module 706 of FIG. 7.

At block 804, users or geographic locations that may improve their loadsby reallocation are identified. This may include identifying machineswith high loads or identifying machines with low loads. These loads may,for instance, vary based on the dynamic changes in usage traffic at anygiven time (e.g., a machine has too many queries at once). The loads mayalso be identified based on any types of usage patterns. The usagepatterns may be identified based on one or more time periods of usage,such as 12 hour periods, 8 hour periods, 4 hour periods, etc.

At block 806, the appropriate reallocation of users or geographiclocations that is beneficial to load balancing is determined. Forexample, with respect to execution of a query, if the initial mapping isto a machine that is overloaded, then the query may be mapped to anothermachine that is underloaded. As another example, two or more groups ofgeographic locations may be banded together based on their complementaryusage patterns in order to optimize the balancing of loads. Thegeographic locations may be banded together in any number ofpermutations which mix and match various numbers of geographic locationsand various time intervals to optimize the load balance for varyingusage patterns. In an embodiment, blocks 804 and 806 may be performed bythe load monitoring module 706 and temporal balancing module 708 of FIG.7.

At block 808, users are mapped to machines based on the reallocation inblock 806. With respect to banded geographic locations, the users of thebanded geographic locations are mapped and routed according to theoptimized configuration determined in block 806. For instance, twocomplementary geographic locations with opposite usage patterns may bemapped and routed to the same machine.

FIG. 9 illustrates an example process of routing a query to a machine(or plurality of closely associated machines, such as a machine pool),according to an embodiment. It should be appreciated that the discussionabove for FIGS. 6-8 may also apply to the process for FIG. 9. For thesake of brevity and clarity, similar features and functions are notrepeated here for FIG. 9, but may be equally applicable.

At block 902 of process 900, a query (or request) is received. Forexample, the system may receive a query initiated by a user of a socialnetworking system. The query may include a user ID for the user alongwith the query. At block 904, a unique ID is determined from the userID. For example, a mapping from the user ID to the unique ID may be usedto convert the user ID to a unique ID. At block 906, a shard number maybe determined based on the unique ID. For example, the shard number maybe determined based on a partition size, as described herein. In anembodiment, blocks 902, 904, and 906 may be performed by the sharddetermination module 702 of FIG. 7.

At block 908, the shard number may be mapped to a physical machine (orplurality of closely associated machines). In one embodiment, the shardnumber is mapped to a physical machine based on equal divisions of theunique ID space to physical machines. In an embodiment, the shard numberis mapped to a physical machine based on unequal divisions of the uniqueID space. In an embodiment, load balancing considerations, as discussedin more detail herein, may also be taken into consideration for themapping of the shard number to a physical machine.

At block 910, a machine is selected. If the shard number is mapped to aplurality of machines, such as a machine pool, then one of the machinesis selected. At block 912, it is determined if the selected machinedynamically rejects the query. If the query is not rejected by theselected machine, then the query is routed to the selected machine andexecuted by the selected machine at block 914. However, if the query isrejected by the selected machine, then another machine may be selected,as represented by the arrow from block 912 back to block 910. Forexample, if the first machine selected from the plurality of machine isrejected, then another machine from the plurality of machines may beselected. This selection process may continue until one of the machinesfrom the plurality of machine accepts the query. In an embodiment, if nomachine from the plurality of machines can be selected to successfullyreceive the query (e.g., due to overload or maintenance), then the querymay be routed to a general purpose pool of machines. If the shard numberwas mapped to a single machine at block 908, and that machine rejectsthe query, then an alternate machine may be selected to receive thequery, such as a machine from a general purpose pool of machines. Inanother embodiment, if a query is rejected by a selected machine, thequery may be resent to the same machine after a predetermined waitingperiod. In an embodiment, blocks 908, 910, 912, and 914 may be performedby the routing module 704, the load monitoring module 706, and thetemporal balancing module 708 of FIG. 7.

Social Networking System—Example Implementation

FIG. 10 is a network diagram of an example system 1000 for substitutingvideo links within a social network in accordance with an embodiment ofthe invention. The system 1000 includes one or more user devices 1010,one or more external systems 1020, a social networking system 1030, anda network 1050. In an embodiment, the social networking system discussedin connection with the embodiments described above may be implemented asthe social networking system 1030. For purposes of illustration, theembodiment of the system 1000, shown by FIG. 10, includes a singleexternal system 1020 and a single user device 1010. However, in otherembodiments, the system 1000 may include more user devices 1010 and/ormore external systems 1020. In certain embodiments, the socialnetworking system 1030 is operated by a social network provider, whereasthe external systems 1020 are separate from the social networking system1030 in that they may be operated by different entities. In variousembodiments, however, the social networking system 1030 and the externalsystems 1020 operate in conjunction to provide social networkingservices to users (or members) of the social networking system 1030. Inthis sense, the social networking system 1030 provides a platform orbackbone, which other systems, such as external systems 1020, may use toprovide social networking services and functionalities to users acrossthe Internet.

The user device 1010 comprises one or more computing devices that canreceive input from a user and transmit and receive data via the network1050. In one embodiment, the user device 1010 is a conventional computersystem executing, for example, a Microsoft Windows compatible operatingsystem (OS), Apple OS X, and/or a Linux distribution. In anotherembodiment, the user device 1010 can be a device having computerfunctionality, such as a smart-phone, a tablet, a personal digitalassistant (PDA), a mobile telephone, etc. The user device 1010 isconfigured to communicate via the network 1050. The user device 1010 canexecute an application, for example, a browser application that allows auser of the user device 1010 to interact with the social networkingsystem 1030. In another embodiment, the user device 1010 interacts withthe social networking system 1030 through an application programminginterface (API) provided by the native operating system of the userdevice 1010, such as iOS and ANDROID. The user device 1010 is configuredto communicate with the external system 1020 and the social networkingsystem 1030 via the network 1050, which may comprise any combination oflocal area and/or wide area networks, using wired and/or wirelesscommunication systems.

In one embodiment, the network 1050 uses standard communicationstechnologies and protocols. Thus, the network 1050 can include linksusing technologies such as Ethernet, 802.11, worldwide interoperabilityfor microwave access (WiMAX), 3G, 4G, CDMA, GSM, LTE, digital subscriberline (DSL), etc. Similarly, the networking protocols used on the network1050 can include multiprotocol label switching (MPLS), transmissioncontrol protocol/Internet protocol (TCP/IP), User Datagram Protocol(UDP), hypertext transport protocol (HTTP), simple mail transferprotocol (SMTP), file transfer protocol (FTP), and the like. The dataexchanged over the network 1050 can be represented using technologiesand/or formats including hypertext markup language (HTML) and extensiblemarkup language (XML). In addition, all or some links can be encryptedusing conventional encryption technologies such as secure sockets layer(SSL), transport layer security (TLS), and Internet Protocol security(IPsec).

In one embodiment, the user device 1010 may display content from theexternal system 1020 and/or from the social networking system 1030 byprocessing a markup language document 1014 received from the externalsystem 1020 and from the social networking system 1030 using a browserapplication 1012. The markup language document 1014 identifies contentand one or more instructions describing formatting or presentation ofthe content. By executing the instructions included in the markuplanguage document 1014, the browser application 1012 displays theidentified content using the format or presentation described by themarkup language document 1014. For example, the markup language document1014 includes instructions for generating and displaying a web pagehaving multiple frames that include text and/or image data retrievedfrom the external system 1020 and the social networking system 1030. Invarious embodiments, the markup language document 1014 comprises a datafile including extensible markup language (XML) data, extensiblehypertext markup language (XHTML) data, or other markup language data.Additionally, the markup language document 1014 may include JavaScriptObject Notation (JSON) data, JSON with padding (JSONP), and JavaScriptdata to facilitate data-interchange between the external system 1020 andthe user device 1010. The browser application 1012 on the user device1010 may use a JavaScript compiler to decode the markup languagedocument 1014.

The markup language document 1014 may also include, or link to,applications or application frameworks such as FLASH™ or Unity™applications, the SilverLight™ application framework, etc.

In one embodiment, the user device 1010 also includes one or morecookies 1016 including data indicating whether a user of the user device1010 is logged into the social networking system 1030, which may enablemodification of the data communicated from the social networking system1030 to the user device 1010.

The external system 1020 includes one or more web servers that includeone or more web pages 1022 a, 1022 b, which are communicated to the userdevice 1010 using the network 1050. The external system 1020 is separatefrom the social networking system 1030. For example, the external system1020 is associated with a first domain, while the social networkingsystem 1030 is associated with a separate social networking domain. Webpages 1022 a, 1022 b, included in the external system 1020, comprisemarkup language documents 1014 identifying content and includinginstructions specifying formatting or presentation of the identifiedcontent.

The social networking system 1030 includes one or more computing devicesfor a social network, including a plurality of users, and providingusers of the social network with the ability to communicate and interactwith other users of the social network. In some instances, the socialnetwork can be represented by a graph, i.e., a data structure includingedges and nodes. Other data structures can also be used to represent thesocial network, including but not limited to databases, objects,classes, meta elements, files, or any other data structure. The socialnetworking system 1030 may be administered, managed, or controlled by anoperator. The operator of the social networking system 1030 may be ahuman being, an automated application, or a series of applications formanaging content, regulating policies, and collecting usage metricswithin the social networking system 1030. Any type of operator may beused.

Users may join the social networking system 1030 and then addconnections to any number of other users of the social networking system1030 to whom they desire to be connected. As used herein, the term“friend” refers to any other user of the social networking system 1030to whom a user has formed a connection, association, or relationship viathe social networking system 1030. For example, in an embodiment, ifusers in the social networking system 1030 are represented as nodes inthe social graph, the term “friend” can refer to an edge formed betweenand directly connecting two user nodes.

Connections may be added explicitly by a user or may be automaticallycreated by the social networking system 1030 based on commoncharacteristics of the users (e.g., users who are alumni of the sameeducational institution). For example, a first user specifically selectsa particular other user to be a friend. Connections in the socialnetworking system 1030 are usually in both directions, but need not be,so the terms “user” and “friend” depend on the frame of reference.Connections between users of the social networking system 1030 areusually bilateral (“two-way”), or “mutual,” but connections may also beunilateral, or “one-way.” For example, if Bob and Joe are both users ofthe social networking system 1030 and connected to each other, Bob andJoe are each other's connections. If, on the other hand, Bob wishes toconnect to Joe to view data communicated to the social networking system1030 by Joe, but Joe does not wish to form a mutual connection, aunilateral connection may be established. The connection between usersmay be a direct connection; however, some embodiments of the socialnetworking system 1030 allow the connection to be indirect via one ormore levels of connections or degrees of separation.

In addition to establishing and maintaining connections between usersand allowing interactions between users, the social networking system1030 provides users with the ability to take actions on various types ofitems supported by the social networking system 1030. These items mayinclude groups or networks (i.e., social networks of people, entities,and concepts) to which users of the social networking system 1030 maybelong, events or calendar entries in which a user might be interested,computer-based applications that a user may use via the socialnetworking system 1030, transactions that allow users to buy or sellitems via services provided by or through the social networking system1030, and interactions with advertisements that a user may perform on oroff the social networking system 1030. These are just a few examples ofthe items upon which a user may act on the social networking system1030, and many others are possible. A user may interact with anythingthat is capable of being represented in the social networking system1030 or in the external system 1020, separate from the social networkingsystem 1030, or coupled to the social networking system 1030 via thenetwork 1050.

The social networking system 1030 is also capable of linking a varietyof entities. For example, the social networking system 1030 enablesusers to interact with each other as well as external systems 1020 orother entities through an API, a web service, or other communicationchannels. The social networking system 1030 generates and maintains the“social graph” comprising a plurality of nodes interconnected by aplurality of edges. Each node in the social graph may represent anentity that can act on another node and/or that can be acted on byanother node. The social graph may include various types of nodes.Examples of types of nodes include users, non-person entities, contentitems, web pages, groups, activities, messages, concepts, and any otherthings that can be represented by an object in the social networkingsystem 1030. An edge between two nodes in the social graph may representa particular kind of connection, or association, between the two nodes,which may result from node relationships or from an action that wasperformed by one of the nodes on the other node. In some cases, theedges between nodes can be weighted. The weight of an edge can representan attribute associated with the edge, such as a strength of theconnection or association between nodes. Different types of edges can beprovided with different weights. For example, an edge created when oneuser “likes” another user may be given one weight, while an edge createdwhen a user befriends another user may be given a different weight.

As an example, when a first user identifies a second user as a friend,an edge in the social graph is generated connecting a node representingthe first user and a second node representing the second user. Asvarious nodes relate or interact with each other, the social networkingsystem 1030 modifies edges connecting the various nodes to reflect therelationships and interactions.

The social networking system 1030 also includes user-generated content,which enhances a user's interactions with the social networking system1030. User-generated content may include anything a user can add,upload, send, or “post” to the social networking system 1030. Forexample, a user communicates posts to the social networking system 1030from a user device 1010. Posts may include data such as status updatesor other textual data, location information, images such as photos,videos, links, music or other similar data and/or media. Content mayalso be added to the social networking system 1030 by a third party.Content “items” are represented as objects in the social networkingsystem 1030. In this way, users of the social networking system 1030 areencouraged to communicate with each other by posting text and contentitems of various types of media through various communication channels.Such communication increases the interaction of users with each otherand increases the frequency with which users interact with the socialnetworking system 1030.

The social networking system 1030 includes a web server 1032, an APIrequest server 1034, a user profile store 1036, a connection store 1038,an action logger 1040, an activity log 1042, an authorization server1044, and a video substitution module 1046. In an embodiment of theinvention, the social networking system 1030 may include additional,fewer, or different components for various applications. Othercomponents, such as network interfaces, security mechanisms, loadbalancers, failover servers, management and network operations consoles,and the like are not shown so as to not obscure the details of thesystem.

The user profile store 1036 maintains information about user accounts,including biographic, demographic, and other types of descriptiveinformation, such as work experience, educational history, hobbies orpreferences, location, and the like that has been declared by users orinferred by the social networking system 1030. This information isstored in the user profile store 1036 such that each user is uniquelyidentified. The social networking system 1030 also stores datadescribing one or more connections between different users in theconnection store 1038. The connection information may indicate users whohave similar or common work experience, group memberships, hobbies, oreducational history. Additionally, the social networking system 1030includes user-defined connections between different users, allowingusers to specify their relationships with other users. For example,user-defined connections allow users to generate relationships withother users that parallel the users' real-life relationships, such asfriends, co-workers, partners, and so forth. Users may select frompredefined types of connections, or define their own connection types asneeded. Connections with other nodes in the social networking system1030, such as non-person entities, buckets, cluster centers, images,interests, pages, external systems, concepts, and the like are alsostored in the connection store 1038.

The social networking system 1030 maintains data about objects withwhich a user may interact. To maintain this data, the user profile store1036 and the connection store 1038 store instances of the correspondingtype of objects maintained by the social networking system 1030. Eachobject type has information fields that are suitable for storinginformation appropriate to the type of object. For example, the userprofile store 1036 contains data structures with fields suitable fordescribing a user's account and information related to a user's account.When a new object of a particular type is created, the social networkingsystem 1030 initializes a new data structure of the corresponding type,assigns a unique object identifier to it, and begins to add data to theobject as needed. This might occur, for example, when a user becomes auser of the social networking system 1030, the social networking system1030 generates a new instance of a user profile in the user profilestore 1036, assigns a unique identifier to the user account, and beginsto populate the fields of the user account with information provided bythe user.

The connection store 1038 includes data structures suitable fordescribing a user's connections to other users, connections to externalsystems 1020 or connections to other entities. The connection store 1038may also associate a connection type with a user's connections, whichmay be used in conjunction with the user's privacy setting to regulateaccess to information about the user. In an embodiment of the invention,the user profile store 1036 and the connection store 1038 may beimplemented as a federated database.

Data stored in the connection store 1038, the user profile store 1036,and the activity log 1042 enables the social networking system 1030 togenerate the social graph that uses nodes to identify various objectsand edges connecting nodes to identify relationships between differentobjects. For example, if a first user establishes a connection with asecond user in the social networking system 1030, user accounts of thefirst user and the second user from the user profile store 1036 may actas nodes in the social graph. The connection between the first user andthe second user stored by the connection store 1038 is an edge betweenthe nodes associated with the first user and the second user. Continuingthis example, the second user may then send the first user a messagewithin the social networking system 1030. The action of sending themessage, which may be stored, is another edge between the two nodes inthe social graph representing the first user and the second user.Additionally, the message itself may be identified and included in thesocial graph as another node connected to the nodes representing thefirst user and the second user.

In another example, a first user may tag a second user in an image thatis maintained by the social networking system 1030 (or, alternatively,in an image maintained by another system outside of the socialnetworking system 1030). The image may itself be represented as a nodein the social networking system 1030. This tagging action may createedges between the first user and the second user as well as create anedge between each of the users and the image, which is also a node inthe social graph. In yet another example, if a user confirms attendingan event, the user and the event are nodes obtained from the userprofile store 1036, where the attendance of the event is an edge betweenthe nodes that may be retrieved from the activity log 1042. Bygenerating and maintaining the social graph, the social networkingsystem 1030 includes data describing many different types of objects andthe interactions and connections among those objects, providing a richsource of socially relevant information.

The web server 1032 links the social networking system 1030 to one ormore user devices 1010 and/or one or more external systems 1020 via thenetwork 1050. The web server 1032 serves web pages, as well as otherweb-related content, such as Java, JavaScript, Flash, XML, and so forth.The web server 1032 may include a mail server or other messagingfunctionality for receiving and routing messages between the socialnetworking system 1030 and one or more user devices 1010. The messagescan be instant messages, queued messages (e.g., email), text and SMSmessages, or any other suitable messaging format.

The API request server 1034 allows one or more external systems 1020 anduser devices 1010 to call access information from the social networkingsystem 1030 by calling one or more API functions. The API request server1034 may also allow external systems 1020 to send information to thesocial networking system 1030 by calling APIs. The external system 1020,in one embodiment, sends an API request to the social networking system1030 via the network 1050, and the API request server 1034 receives theAPI request. The API request server 1034 processes the request bycalling an API associated with the API request to generate anappropriate response, which the API request server 1034 communicates tothe external system 1020 via the network 1050. For example, responsiveto an API request, the API request server 1034 collects data associatedwith a user, such as the user's connections that have logged into theexternal system 1020, and communicates the collected data to theexternal system 1020. In another embodiment, the user device 1010communicates with the social networking system 1030 via APIs in the samemanner as external systems 1020.

The action logger 1040 is capable of receiving communications from theweb server 1032 about user actions on and/or off the social networkingsystem 1030. The action logger 1040 populates the activity log 1042 withinformation about user actions, enabling the social networking system1030 to discover various actions taken by its users within the socialnetworking system 1030 and outside of the social networking system 1030.Any action that a particular user takes with respect to another node onthe social networking system 1030 may be associated with each user'saccount, through information maintained in the activity log 1042 or in asimilar database or other data repository. Examples of actions taken bya user within the social networking system 1030 that are identified andstored may include, for example, adding a connection to another user,sending a message to another user, reading a message from another user,viewing content associated with another user, attending an event postedby another user, posting an image, attempting to post an image, or otheractions interacting with another user or another object. When a usertakes an action within the social networking system 1030, the action isrecorded in the activity log 1042. In one embodiment, the socialnetworking system 1030 maintains the activity log 1042 as a database ofentries. When an action is taken within the social networking system1030, an entry for the action is added to the activity log 1042. Theactivity log 1042 may be referred to as an action log.

Additionally, user actions may be associated with concepts and actionsthat occur within an entity outside of the social networking system1030, such as an external system 1020 that is separate from the socialnetworking system 1030. For example, the action logger 1040 may receivedata describing a user's interaction with an external system 1020 fromthe web server 1032. In this example, the external system 1020 reports auser's interaction according to structured actions and objects in thesocial graph.

Other examples of actions where a user interacts with an external system1020 include a user expressing an interest in an external system 1020 oranother entity, a user posting a comment to the social networking system1030 that discusses an external system 1020 or a web page 1022 a withinthe external system 1020, a user posting to the social networking system1030 a Uniform Resource Locator (URL) or other identifier associatedwith an external system 1020, a user attending an event associated withan external system 1020, or any other action by a user that is relatedto an external system 1020. Thus, the activity log 1042 may includeactions describing interactions between a user of the social networkingsystem 1030 and an external system 1020 that is separate from the socialnetworking system 1030.

The authorization server 1044 enforces one or more privacy settings ofthe users of the social networking system 1030. A privacy setting of auser determines how particular information associated with a user can beshared. The privacy setting comprises the specification of particularinformation associated with a user and the specification of the entityor entities with whom the information can be shared. Examples ofentities with which information can be shared may include other users,applications, external systems 1020, or any entity that can potentiallyaccess the information. The information that can be shared by a usercomprises user account information, such as profile photos, phonenumbers associated with the user, user's connections, actions taken bythe user such as adding a connection, changing user profile information,and the like.

The privacy setting specification may be provided at different levels ofgranularity. For example, the privacy setting may identify specificinformation to be shared with other users; the privacy settingidentifies a work phone number or a specific set of related information,such as, personal information including profile photo, home phonenumber, and status. Alternatively, the privacy setting may apply to allthe information associated with the user. The specification of the setof entities that can access particular information can also be specifiedat various levels of granularity. Various sets of entities with whichinformation can be shared may include, for example, all friends of theuser, all friends of friends, all applications, or all external systems1020. One embodiment allows the specification of the set of entities tocomprise an enumeration of entities. For example, the user may provide alist of external systems 1020 that are allowed to access certaininformation. Another embodiment allows the specification to comprise aset of entities along with exceptions that are not allowed to access theinformation. For example, a user may allow all external systems 1020 toaccess the user's work information, but specify a list of externalsystems 1020 that are not allowed to access the work information.Certain embodiments call the list of exceptions that are not allowed toaccess certain information a “block list”. External systems 1020belonging to a block list specified by a user are blocked from accessingthe information specified in the privacy setting. Various combinationsof granularity of specification of information, and granularity ofspecification of entities, with which information is shared arepossible. For example, all personal information may be shared withfriends whereas all work information may be shared with friends offriends.

The authorization server 1044 contains logic to determine if certaininformation associated with a user can be accessed by a user's friends,external systems 1020, and/or other applications and entities. Theexternal system 1020 may need authorization from the authorizationserver 1044 to access the user's more private and sensitive information,such as the user's work phone number. Based on the user's privacysettings, the authorization server 1044 determines if another user, theexternal system 1020, an application, or another entity is allowed toaccess information associated with the user, including information aboutactions taken by the user.

The social networking system 1030 may include clustering module 1046.The clustering module 1046 may generate unique IDs and assign them tonodes of a social graph. Furthermore, the clustering module 1046 mayutilize the unique IDs to partition the social graph over the socialnetworking system 1030. The unique ID space may be used to map users tomachines (e.g., database servers or caching systems) of the socialnetworking system 1030. The clustering module 1046 may route users ofthe social networking system 1030 to the machines based on the mapping.The clustering module 1046 may map or route users to machines based onload balancing considerations, such as traffic usage patterns, orwhether machines are overloaded or underloaded. In an embodiment, theclustering module 1046 may be implemented as the clustering module 1046of FIG. 1.

Hardware Implementation

The foregoing processes and features can be implemented by a widevariety of machine and computer system architectures and in a widevariety of network and computing environments. FIG. 11 illustrates anexample of a computer system 1100 that may be used to implement one ormore of the embodiments described herein in accordance with anembodiment of the invention. The computer system 1100 includes sets ofinstructions for causing the computer system 1100 to perform theprocesses and features discussed herein. The computer system 1100 may beconnected (e.g., networked) to other machines. In a networkeddeployment, the computer system 1100 may operate in the capacity of aserver machine or a client machine in a client-server networkenvironment, or as a peer machine in a peer-to-peer (or distributed)network environment. In an embodiment of the invention, the computersystem 1100 may be a component of the social networking system describedherein. In an embodiment of the invention, the computer system 1100 maybe one server among many that constitutes all or part of the socialnetworking system 730.

The computer system 1100 includes a processor 1102, a cache 1104, andone or more executable modules and drivers, stored on acomputer-readable medium, directed to the processes and featuresdescribed herein. Additionally, the computer system 1100 includes a highperformance input/output (I/O) bus 1106 and a standard I/O bus 1108. Ahost bridge 1110 couples processor 1102 to high performance I/O bus1106, whereas I/O bus bridge 1112 couples the two buses 1106 and 1108 toeach other. A system memory 1114 and one or more network interfaces 1116couple to high performance I/O bus 1106. The computer system 1100 mayfurther include video memory and a display device coupled to the videomemory (not shown). Mass storage 1118 and I/O ports 1120 couple to thestandard I/O bus 1108. The computer system 1100 may optionally include akeyboard and pointing device, a display device, or other input/outputdevices (not shown) coupled to the standard I/O bus 1108. Collectively,these elements are intended to represent a broad category of computerhardware systems, including but not limited to computer systems based onthe x86-compatible processors manufactured by Intel Corporation of SantaClara, Calif., and the x86-compatible processors manufactured byAdvanced Micro Devices (AMD), Inc., of Sunnyvale, Calif., as well as anyother suitable processor.

An operating system manages and controls the operation of the computersystem 1100, including the input and output of data to and from softwareapplications (not shown). The operating system provides an interfacebetween the software applications being executed on the system and thehardware components of the system. Any suitable operating system may beused, such as the LINUX Operating System, the Apple Macintosh OperatingSystem, available from Apple Computer Inc. of Cupertino, Calif., UNIXoperating systems, Microsoft® Windows® operating systems, BSD operatingsystems, and the like. Other implementations are possible.

The elements of the computer system 1100 are described in greater detailbelow. In particular, the network interface 1116 provides communicationbetween the computer system 1100 and any of a wide range of networks,such as an Ethernet (e.g., IEEE 802.3) network, a backplane, etc. Themass storage 1118 provides permanent storage for the data andprogramming instructions to perform the above-described processes andfeatures implemented by the respective computing systems identifiedabove, whereas the system memory 1114 (e.g., DRAM) provides temporarystorage for the data and programming instructions when executed by theprocessor 1102. The I/O ports 1120 may be one or more serial and/orparallel communication ports that provide communication betweenadditional peripheral devices, which may be coupled to the computersystem 1100.

The computer system 1100 may include a variety of system architectures,and various components of the computer system 1100 may be rearranged.For example, the cache 1104 may be on-chip with processor 1102.Alternatively, the cache 1104 and the processor 1102 may be packedtogether as a “processor module”, with processor 1102 being referred toas the “processor core”. Furthermore, certain embodiments of theinvention may neither require nor include all of the above components.For example, peripheral devices coupled to the standard I/O bus 1108 maycouple to the high performance I/O bus 1106. In addition, in someembodiments, only a single bus may exist, with the components of thecomputer system 1100 being coupled to the single bus. Furthermore, thecomputer system 1100 may include additional components, such asadditional processors, storage devices, or memories.

In general, the processes and features described herein may beimplemented as part of an operating system or a specific application,component, program, object, module, or series of instructions referredto as “programs”. For example, one or more programs may be used toexecute specific processes described herein. The programs typicallycomprise one or more instructions in various memory and storage devicesin the computer system 1100 that, when read and executed by one or moreprocessors, cause the computer system 1100 to perform operations toexecute the processes and features described herein. The processes andfeatures described herein may be implemented in software, firmware,hardware (e.g., an application specific integrated circuit), or anycombination thereof.

In one implementation, the processes and features described herein areimplemented as a series of executable modules run by the computer system1100, individually or collectively in a distributed computingenvironment. The foregoing modules may be realized by hardware,executable modules stored on a computer-readable medium (ormachine-readable medium), or a combination of both. For example, themodules may comprise a plurality or series of instructions to beexecuted by a processor in a hardware system, such as the processor1102. Initially, the series of instructions may be stored on a storagedevice, such as the mass storage 1118. However, the series ofinstructions can be stored on any suitable computer readable storagemedium. Furthermore, the series of instructions need not be storedlocally, and could be received from a remote storage device, such as aserver on a network, via the network interface 1116. The instructionsare copied from the storage device, such as the mass storage 1118, intothe system memory 1114 and then accessed and executed by the processor1102. In various implementations, a module or modules can be executed bya processor or multiple processors in one or multiple locations, such asmultiple servers in a parallel processing environment.

Examples of computer-readable media include, but are not limited to,recordable type media such as volatile and non-volatile memory devices;solid state memories; floppy and other removable disks; hard diskdrives; magnetic media; optical disks (e.g., Compact Disk Read-OnlyMemory (CD ROMS), Digital Versatile Disks (DVDs)); other similarnon-transitory (or transitory), tangible (or non-tangible) storagemedium; or any type of medium suitable for storing, encoding, orcarrying a series of instructions for execution by the computer system1100 to perform any one or more of the processes and features describedherein.

For purposes of explanation, numerous specific details are set forth inorder to provide a thorough understanding of the description. It will beapparent, however, to one skilled in the art that embodiments of thedisclosure can be practiced without these specific details. In someinstances, modules, structures, processes, features, and devices areshown in block diagram form in order to avoid obscuring the description.In other instances, functional block diagrams and flow diagrams areshown to represent data and logic flows. The components of blockdiagrams and flow diagrams (e.g., modules, blocks, structures, devices,features, etc.) may be variously combined, separated, removed,reordered, and replaced in a manner other than as expressly describedand depicted herein.

Reference in this specification to “one embodiment”, “an embodiment”,“other embodiments”, “one series of embodiments”, “some embodiments”,“various embodiments”, or the like means that a particular feature,design, structure, or characteristic described in connection with theembodiment is included in at least one embodiment of the disclosure. Theappearances of, for example, the phrase “in one embodiment” or “in anembodiment” in various places in the specification are not necessarilyall referring to the same embodiment, nor are separate or alternativeembodiments mutually exclusive of other embodiments. Moreover, whetheror not there is express reference to an “embodiment” or the like,various features are described, which may be variously combined andincluded in some embodiments, but also variously omitted in otherembodiments. Similarly, various features are described that may bepreferences or requirements for some embodiments, but not otherembodiments.

The language used herein has been principally selected for readabilityand instructional purposes, and it may not have been selected todelineate or circumscribe the inventive subject matter. It is thereforeintended that the scope of the invention be limited not by this detaileddescription, but rather by any claims that issue on an application basedhereon. Accordingly, the disclosure of the embodiments of the inventionis intended to be illustrative, but not limiting, of the scope of theinvention, which is set forth in the following claims.

What is claimed:
 1. A computer implemented method comprising: providing,by a computer system, unique identifiers (IDs) associated with aplurality of nodes, wherein nodes in the plurality of nodes areclustered into one or more respective communities, wherein the nodes areassigned numerically proximate unique IDs based at least in part on therespective communities in which the nodes are clustered, and wherein atleast some of the nodes each reference a user of a social networkingsystem; determining, by the computer system, a number of partitionsassociated with a plurality of machines; segmenting, by the computersystem, the unique IDs into divisions based on the number of partitions;detecting, by the computing system, two or more geographic locationswith complementary traffic usage patterns based at least in part oninteractions in the social networking system among users in the two ormore geographic locations; mapping, by the computer system, the uniqueIDs to the plurality of machines based on the divisions, wherein theunique IDs are mapped so nodes that satisfy a threshold edge weight aremapped to one or more of the same machines in the plurality of machines,and wherein a first node and a second node are determined to be closelyconnected based at least in part an affinity coefficient that measures asocial relationship between a first user corresponding to the first nodeand a second user corresponding to the second node, wherein unique IDsassociated with the two or more geographic locations with complementarytraffic usage patterns are mapped to the same machines, wherein thegeographic locations include a first geographic location having athreshold peak in traffic usage over a period of time and a secondgeographic location having a threshold valley in traffic usage over theperiod of time, and wherein a first node is connected to a second nodeusing at least one weighted edge; and routing, by the computer system,at least one query directed to at least the first node in the pluralityof nodes to at least a first machine in the plurality of machines towhich a unique ID of the first node was mapped.
 2. The method of claim1, wherein the plurality of machines comprises a cache layer.
 3. Themethod of claim 1, further comprising: receiving a query associated witha node; determining a unique ID for the node; determining a machine towhich the node is mapped based on the unique ID; and routing the queryto the machine.
 4. The method of claim 1, further comprising determininga unique ID associated with a node based on a mapping of previouslyassigned IDs to the unique IDs.
 5. The method of claim 1, furthercomprising: receiving a query associated with a node; determining aunique ID for the node; determining a first machine to which the node ismapped based on the unique ID; detecting that a load of the machineexceeds a threshold; and routing the query to a second machine.
 6. Themethod of claim 1, wherein the two or more geographic locations arecountries.
 7. The method of claim 1, wherein the complementary trafficusage patterns comprise high traffic usage and low traffic usageaccording to time.
 8. The method of claim 1, further comprisingdetermining an impact to locality, wherein the mapping unique IDs is inresponse to the determined impact.
 9. The method of claim 1, furthercomprising: receiving a query associated with a unique ID associatedwith one of the two or more geographic locations; and routing the queryto the machine.
 10. The method of claim 1, further comprising: detectingtwo or more geographic locations having different time zones; andmapping unique IDs associated with the two or more geographic locationsto a machine.
 11. The method of claim 1, further comprising: detecting amachine having a load below a threshold; and mapping additional uniqueIDs to the machine.
 12. The method of claim 1, further comprising:detecting a machine having a load above a threshold; and mapping atleast one unique ID away from the machine.
 13. The method of claim 1,further comprising: identifying a prohibited application associated withan unused shard of a machine, the prohibited application unavailable tousers associated with a first geographic location; and mappingadditional unique IDs to the unused shard of the machine, the additionalunique IDs associated with users associated with a second geographiclocation.
 14. The method of claim 1, wherein the mapping the unique IDsto the plurality of machines comprises evenly distributing the uniqueIDs.
 15. The method of claim 1, wherein the mapping the unique IDs tothe plurality of machines comprises unevenly distributing the uniqueIDs.
 16. The method of claim 1, wherein the plurality of nodes isassociated with users of a social networking system.
 17. The method ofclaim 1, wherein the plurality of nodes is associated with at least oneof persons, non-persons, organizations, content, events, web pages,communications, objects, or concepts.
 18. A system comprising: at leastone processor, and a memory storing instructions configured to instructthe at least one processor to perform: providing unique identifiers(IDs) associated with a plurality of nodes, wherein nodes in theplurality of nodes are clustered into one or more respectivecommunities, wherein the nodes are assigned numerically proximate uniqueIDs based at least in part on the respective communities in which thenodes are clustered, and wherein at least some of the nodes eachreference a user of a social networking system; determining a number ofpartitions associated with a plurality of machines; segmenting theunique IDs into divisions based on the number of partitions; detectingtwo or more geographic locations with complementary traffic usagepatterns based at least in part on interactions in the social networkingsystem among users in the two or more geographic locations; mapping theunique IDs to the plurality of machines based on the divisions, whereinthe unique IDs are mapped so nodes that satisfy a threshold edge weightare mapped to one or more of the same machines in the plurality ofmachines, and wherein a first node and a second node are determined tobe closely connected based at least in part an affinity coefficient thatmeasures a social relationship between a first user corresponding to thefirst node and a second user corresponding to the second node, whereinunique IDs associated with the two or more geographic locations withcomplementary traffic usage patterns are mapped to the same machines,wherein the geographic locations include a first geographic locationhaving a threshold peak in traffic usage over a period of time and asecond geographic location having a threshold valley in traffic usageover the period of time, and wherein a first node is connected to asecond node using at least one weighted edge; and routing at least onequery directed to at least the first node in the plurality of nodes toat least a first machine in the plurality of machines to which a uniqueID of the first node was mapped.
 19. A non-transitory computer storagemedium storing computer-executable instructions that, when executed,cause a computer system to perform computer-implemented methodcomprising: providing unique identifiers (IDs) associated with aplurality of nodes, wherein nodes in the plurality of nodes areclustered into one or more respective communities, wherein the nodes areassigned numerically proximate unique IDs based at least in part on therespective communities in which the nodes are clustered, and wherein atleast some of the nodes each reference a user of a social networkingsystem; determining a number of partitions associated with a pluralityof machines; segmenting the unique IDs into divisions based on thenumber of partitions; detecting two or more geographic locations withcomplementary traffic usage patterns based at least in part oninteractions in the social networking system among users in the two ormore geographic locations; mapping the unique IDs to the plurality ofmachines based on the divisions, wherein the unique IDs are mapped sonodes that satisfy a threshold edge weight are mapped to one or more ofthe same machines in the plurality of machines, and wherein a first nodeand a second node are determined to be closely connected based at leastin part an affinity coefficient that measures a social relationshipbetween a first user corresponding to the first node and a second usercorresponding to the second node, wherein unique IDs associated with thetwo or more geographic locations with complementary traffic usagepatterns are mapped to the same machines, wherein the geographiclocations include a first geographic location having a threshold peak intraffic usage over a period of time and a second geographic locationhaving a threshold valley in traffic usage over the period of time, andwherein a first node is connected to a second node using at least oneweighted edge; and routing at least one query directed to at least thefirst node in the plurality of nodes to at least a first machine in theplurality of machines to which a unique ID of the first node was mapped.